const timerSize = 20;
var GlobalTimer;
function Timer(interval)	// extends Sprite
{
    Sprite.apply(this);
    this.buttonMode = false;
    this.mouseChildren = false;
    this.running = false;
    this.time = 0;
    this.intervalID;
    this.interval = interval;    
    
    // method association
    this.TimerStart = TimerStart;
    this.TimerStop = TimerStop;
    this.TimerRun = TimerRun;
    this.getTime = getTime;
    
    /*t.setTextFormat(Timer.tFormat);
    t.x = timerSize/4; 
    t.y = timerSize/4;
    this.addChild(t,0);*/
     
    /*this.redraw = function(){
        var textChild = this.getChildAt(0);  
        textChild.text = "time: " + Math.floor(this.time/10)+"."+(this.time%10);
        textChild.width = t.textWidth; 
        textChild.height = t.textHeight;
    }*/ 
        
    
	
}

Timer.prototype = new Sprite();
function TimerStart (){
    GlobalTimer = this;
    this.intervalID = window.setInterval(this.TimerRun,this.interval);
    this.running = true;
}

function TimerStop (){
    window.clearInterval(this.intervalID);
    this.running = false;
    GlobalTimer = null;
}

function TimerRun (){
        if (GlobalTimer.running){
            GlobalTimer.time++;
            GlobalTimer.parent.Run();
        }
}

function getTime (){
    return this.time;
}